﻿namespace OleDbDAL.Systems
{
    using DBUtility;
    using IDal.Systems;
    using Model.Systems;
    using System;
    using System.Data;
    using System.Text;

    public class helpsApp : Ihelps
    {
        private string dbname = "Helps";

        public void Add(helpsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into helps(");
            builder.Append("helpid,helpTitle,helpRemark,helpLastUpdateTime,helpMoveAddress");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.helpid + ",");
            builder.Append("'" + model.helpTitle + "',");
            builder.Append("'" + model.helpRemark + "',");
            builder.Append("'" + model.helpLastUpdateTime + "',");
            builder.Append("'" + model.helpMoveAddress + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int helpid)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete helps ");
            builder.Append(" where helpid=" + helpid);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from helps ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by helpid ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "helpid", "helps", swhere);
        }

        public helpsEnt GetModel(int helpid)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select helpid,helpTitle,helpRemark,helpLastUpdateTime,helpMoveAddress from helps ");
            builder.Append(" where helpid=" + helpid);
            helpsEnt ent = new helpsEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.helpid = helpid;
            if (table.Rows.Count > 0)
            {
                ent.helpTitle = table.Rows[0]["helpTitle"].ToString();
                ent.helpRemark = table.Rows[0]["helpRemark"].ToString();
                if (table.Rows[0]["helpLastUpdateTime"].ToString() != "")
                {
                    ent.helpLastUpdateTime = DateTime.Parse(table.Rows[0]["helpLastUpdateTime"].ToString());
                }
                ent.helpMoveAddress = table.Rows[0]["helpMoveAddress"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from helps ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "helpid");
        }

        public void Update(helpsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update helps set ");
            builder.Append("helpTitle='" + model.helpTitle + "',");
            builder.Append("helpRemark='" + model.helpRemark + "',");
            builder.Append("helpLastUpdateTime='" + model.helpLastUpdateTime + "',");
            builder.Append("helpMoveAddress='" + model.helpMoveAddress + "'");
            builder.Append(" where helpid=" + model.helpid + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

